<?php
/**
 * Created by PhpStorm.
 * User: teddy
 * Date: 15-12-21
 * Time: 下午2:38
 */

/*载入实体类*/
include_once "User.php";

/*数据库链接*/
$mysqli = new mysqli('localhost','root','1','DTXMB');

/*判断链接状态*/
if (mysqli_connect_errno())
{
    echo "{" . '"error"' . ":" . mysqli_connect_error() . "}";
}

/*Sql语句*/
$sql = "select * from Custom";

/*设置UTF8*/
$mysqli->query("set character set 'utf8'");
$mysqli->query("set names 'utf8'");

/*取数据*/
$results = $mysqli->query($sql);
$data = array();

/*把数据放在Array中*/
while($row = $results->fetch_assoc())
{
    $user = new User();
    $user->id = $row["id"];
    /*有中文，所以要进行encode，然后再decode*/
    $user->address = urlencode($row["address"]);
    $user->tel = $row["tel"];
    $user->name = $row["name"];
    $user->pwd = $row["pwd"];
    $user->status = $row["status"];
    $data[] = $user;
}

/*把返回值输出*/
$json = urldecode(json_encode($data));
echo "{" . '"user"' . ":" . $json . "}";

/*释放资源*/
$results->free();

/*关闭链接*/
$mysqli->close();